<!--  -->
<template>
  <div class="main">
    <h2>信用卡申请管理</h2>
    <!-- <el-button type="primary" style="margin:20px" @click="()=>{editType=1;editVisible=true;title='添加状态';orgType.id='无需填写'}">添加分类</el-button> -->
    <div id="search-card">
      <div id="search-content">
        <el-form v-model="search" :inline="true">

          <el-form-item label="会员姓名">
            <el-input v-model="search.username" />
          </el-form-item>

          <el-form-item label="银行名称">
            <el-input v-model="search.bankName" />
          </el-form-item>

          <el-form-item label="电话">
            <el-input v-model="search.phone" />
          </el-form-item>

          <el-form-item label="身份证号">
            <el-input v-model="search.idCard" />
          </el-form-item>

          <el-form-item label="申请结果">
            <el-select v-model="search.result" placeholder="请选择">
              <el-option key="-1" label="已回绝" value="-1" />
              <el-option key="0" label="待处理" value="0" />
              <el-option key="1" label="已成功" value="1" />
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" style="margin-left:10px" @click="conditionQuery">查找</el-button>
          </el-form-item>

          <el-form-item label="模糊查询:">
            <el-input v-model="mohu" />
          </el-form-item>

          <el-form-item>
            <el-button type="primary" style="margin-left:10px" @click="mohuQuery">查找</el-button>
          </el-form-item>
        </el-form>
      </div>

    </div>
    <div id="table-area" style="width: 100%">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >
        <el-table-column
          align="center"
          prop="id"
          label="Id"
          min-width="5%"
        />

        <el-table-column
          align="center"
          prop="userName"
          label="客户姓名"
          min-width="10%"
        />

        <el-table-column
          align="center"
          prop="bankName"
          label="银行名称"
          min-width="20%"
        />

        <el-table-column
          align="center"
          prop="phone"
          label="手机号"
          min-width="10%"
        />

        <el-table-column
          align="center"
          prop="userIdcard"
          label="身份证号"
          min-width="15%"
        />

        <el-table-column
          align="center"
          prop="createTime"
          label="申请时间"
          min-width="10%"
        >
          <template slot-scope="scope">{{ scope.row.createTime| dateYMDHMSFormat }}</template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="result"
          label="申请结果"
          min-width="10%"
        >
          <template slot-scope="Scope">
            <span v-if="Scope.row.result==-1" style="color:red">已回绝</span>
            <span v-if="Scope.row.result==0">待处理</span>
            <span v-if="Scope.row.result==1" style="color:green">已成功</span>
          </template>
        </el-table-column>

        <el-table-column align="center" label="操作" min-width="20%">
          <template slot-scope="Scope">
            <el-button type="primary" icon="el-icon-edit" @click="statusVisible=true; apply.id=Scope.row.id">修改状态</el-button>

          </template>
        </el-table-column>
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5,10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>

    </div>

    <el-dialog title="修改申请状态" :visible.sync="statusVisible" :close-on-click-modal="false">
      <el-form :model="apply">

        <el-form-item label="状态：">
          <el-select v-model="apply.status" placeholder="请选择">
            <el-option key="-1" label="已回绝" value="-1" />
            <el-option key="0" label="待处理" value="0" />
            <el-option key="1" label="已通过" value="1" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleUpdate">修 改</el-button>
        <el-button @click="statusVisible=false">返 回</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { getAllApply, updateApply, conditionSearch, mohuSearch } from '@/api/creditApply'
export default {
  name: 'OrgType',
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      list: [],
      listLoading: true,
      statusVisible: false,
      apply: {},
      search: {},
      mohu: '',
      editType: 0, // 添加 1  修改 2,
      title: ''
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.fetchData()
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    handleSizeChange: function(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    fetchData() {
      this.listLoading = true
      getAllApply().then((data) => {
        this.list = data.obj
        this.listLoading = false
      })
    },

    handleUpdate() {
      console.log('id ' + this.apply.id + ';status ' + this.apply.status)
      updateApply(this.apply.id, this.apply.status).then(() => {
        this.$notify({
          title: '操作成功',
          type: 'success'
        })
        this.fetchData()
        this.statusVisible = false
      })
    },
    conditionQuery() {
      console.log(this.search)
      conditionSearch(this.search).then((data) => {
        this.list = data.obj
        this.search = {}
        this.currentPage = 1
      })
    },
    mohuQuery() {
      console.log(this.mohu)
      mohuSearch(this.mohu).then((data) => {
        this.list = data.obj
        this.currentPage = 1
      })
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style  scoped>
  #main{
        margin-left: 5px;
        margin-right: 5px;

    }

    #table-area{
        margin-left: 10px;
        margin-right: 10px;
    }

    #search-card {
        margin-left: 50px;
        width: 100%;
        height: 120px;
        overflow-x: hidden;
      }
</style>
